using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using DAL;
using Utility;

public partial class Admin_donhang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == "")
        {
            Response.Redirect("dangnhap.aspx");
        }
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
        int total = 0;
        Criteria cri = new Criteria();
        PagerV2_8_1.PageSize = int.Parse(ConfigurationManager.AppSettings["pagesize"]);
        Repeater1.DataSource = tbdonhangBUS.GET(cri.Criter, PagerV2_8_1.CurrentIndex, PagerV2_8_1.PageSize, tbdonhangDTOColumn.Madh.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataBind();
        PagerV2_8_1.ItemCount = total;
        if (PagerV2_8_1.ItemCount <= PagerV2_8_1.PageSize)
            PagerV2_8_1.Visible = false;
        else
            PagerV2_8_1.Visible = true;
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {

            tbdonhangDTO donhang = (tbdonhangDTO)e.Item.DataItem;


            tbkhachhangDTO kh = tbkhachhangBUS.GetByID(donhang.Makh);
            if (kh != null)
            {
                Literal lit_khachhang = (Literal)e.Item.FindControl("lit_KhachHang");
                lit_khachhang.Text = kh.Tenkh;
            }
            HyperLink hyp_dh = (HyperLink)e.Item.FindControl("hyp_DonHang");
            hyp_dh.Text = donhang.Madh.ToString();
            hyp_dh.NavigateUrl = "chitietdonhang.aspx?id=" + donhang.Madh.ToString();
        }
    }
    protected void PagerV2_8_1_Command(object sender, CommandEventArgs e)
    {
        PagerV2_8_1.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
}
